/* ========================================================================
 * PROJECT: FTIR Blob Tracker
 * ========================================================================
 * This work is based on the original FTIR Blob Tracker developed by
 *   Woonhyuk Baek
 *   Woontack Woo
 *   U-VR Lab, GIST of Gwangju in Korea.
 * 
 *   http://uvr.gist.ac.kr/
 *
 * Copyright of the derived and new portions of this work
 *     (C) 2009 GIST U-VR Lab.
 *
 * This framework is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This framework is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this framework; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * For further information please contact 
 *   Woonhyuk Baek
 *   <windage@live.com>
 *   GIST U-VR Lab.
 *   Department of Information and Communication
 *   Gwangju Institute of Science and Technology
 *   1, Oryong-dong, Buk-gu, Gwangju
 *   South Korea
 * ========================================================================
 ** @author   Woonhyuk Baek
 * ======================================================================== */

#ifndef _WARPPING_H_
#define _WARPPING_H_

#include <cv.h>
#include "../Calibration/Calibration.h"
#include "../Calibration/wMatrix.h"

namespace windage
{
	class Warpping
	{
	private:
		Calibration* calibration;
		IplImage* dstMapX;
		IplImage* dstMapY;
		int width;
		int height;
		int translationX;
		int translationY;
		double scale;
		
	public:
		Warpping()
		{
			width = 320;
			height = 240;
			translationX = 0;
			translationY = 0;

			calibration = NULL;
			dstMapX = NULL;
			dstMapY = NULL;

			scale = 1.0;
		}
		~Warpping()
		{
			if(dstMapX) cvReleaseImage(&dstMapX);
			if(dstMapY) cvReleaseImage(&dstMapY);
		}

		void Initialize(int width, int height);
		inline void SetScale(double scale=1.0){this->scale = scale;};
		inline void AttatchCalibration(Calibration* calibration){this->calibration = calibration;};
		bool UpdateWarppingParameter(bool undistortion=true, windage::Matrix3* homography=NULL);
		bool Do(IplImage* src, IplImage* dst);

		inline void SetTranslation(int x, int y){this->translationX=x; this->translationY=y;};
		inline CvSize GetTranslation(){return cvSize(translationX, translationY);};
		inline CvSize GetSize(){return cvSize(width, height);};
		

	};
}

#endif